from django.db import models
from django.contrib.auth import get_user_model
User = get_user_model()


class WorkFlow(models.Model):
    STATUS = (
        (-1, '已取消'),
        (0, '待审核'),
        (1, '未通过'),
        (2, '待发布'),
        (3, '已发布'),
    )
    name = models.CharField(max_length=100, unique=True, verbose_name='工单名')
    title = models.CharField(max_length=100, unique=True, verbose_name='工单名称标题')
    type = models.CharField(max_length=100, unique=True, verbose_name='工单类型')
    status = models.IntegerField(default=0, choices=STATUS, verbose_name='工单状态')
    content = models.TextField(verbose_name='工单内容')
    apply_user = models.ForeignKey(User, verbose_name='提交人', related_name='applied_work', on_delete=models.CASCADE)
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    result = models.TextField(null=True, verbose_name='处理结果')

    class Meta:
        verbose_name = '工单系统'
        verbose_name_plural = '工单系统'
        default_permissions = ()
        permissions = (
            ('view_task', '查看工单'),
            ('add_task', '添加工单'),
            ('change_task', '编辑工单'),
            ('delete_task', '删除工单'),
            ('review_task', '审核工单'),
            ('release_task', '发布工单'),
            ('view_history', '查看工单历史')
        )





